/*
-------------------------------------------------------------------
BIE is Copyright 2001-2004 Brunswick Corp.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/bie_license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------

*/
package tests.prefs;

import java.util.prefs.*;
import java.io.*;

public class PreferenceGenerator {
    public static boolean contains(Preferences node, String key) {
        return node.get(key, null) != null;
    }

    public static String containsValue(Preferences node, String value) {
        try {
            // Get all the keys
            String[] keys = node.keys();
    
            // Scan the keys
            for (int i=0; i<keys.length; i++) {
                if (value.equals(node.get(keys[i], null))) {
                    return keys[i];
                }
            }
        } catch (BackingStoreException e) {
        }
        return null;
    }
    
   public static void main(String[] args) throws Exception{
               
        //set route info
        Preferences prefs = Preferences.systemRoot().node("/xbotts/system");        
        
        //set up xbotts node
        prefs.putInt("maxThreads",10);
        prefs.putInt("shutdownThreadWait",20);
        prefs.put("mailServer","wdinotes1");
        prefs.put("smtpHost","wdinotes1");
        prefs.put("logLevel","FINEST");
        prefs.put("logDirectory","c:/xfiles/logs");
        
        //set File System info
        prefs = Preferences.systemRoot().node("/xbotts/system/filesystem");
        
        prefs.put("inboundAtticDirectory","c:/xfiles/attic/inbound");
        prefs.put("inboundErrorDirectory","c:/xfiles/error/inbound");
        prefs.put("inboundTempDirectory","c:/xfiles/temp/inbound");
        prefs.put("outboundAtticDirectory","c:/xfiles/attic/outbound");
        prefs.put("outboundErrorDirectory","c:/xfiles/error/outbound");
        prefs.put("outboundTempDirectory","c:/xfiles/temp/outbound");
                

        //set notification info
        prefs = Preferences.systemRoot().node("/xbotts/system/notification");
        
        prefs.put("criticalErrorMailToList","");
        prefs.put("errorMailToList","");
        prefs.put("transactionMailToList","");
        prefs.put("translationErrorMailToList","");        
        prefs.putInt("mailOnCriticalError",0);
        prefs.putInt("mailOnError",0);
        prefs.putInt("mailOnTransaction",0);
        prefs.putInt("mailOnTranslationError",0);
        
                
        //set Services info
        prefs = Preferences.systemRoot().node("/xbotts/system/services/soaprpclistener");       
        prefs.put("className","com.webdeninteractive.xbotts.client.serviceproviders.SoapRPCListener");
        prefs.put("type","SoapRPC");
        prefs.putInt("run",1);
        
        //set Services info
        prefs = Preferences.systemRoot().node("/xbotts/system/services/filesystemlistener");       
        prefs.put("className","com.webdeninteractive.xbotts.client.serviceproviders.FileSystemListener");
        prefs.put("type","FileSystem");
        prefs.putInt("run",1);
        prefs.put("watchDirectory","c:/xfiles/watch");
        prefs.putInt("watchInterval",10);
                
        //set Services info
        prefs = Preferences.systemRoot().node("/xbotts/system/services/ftplistener");       
        prefs.put("className","com.webdeninteractive.xbotts.client.serviceproviders.FTPListener");
        prefs.put("type","FTP");
        prefs.putInt("run",1);
        prefs.putInt("port",5802);
        prefs.put("dataDirectory","c:/xfiles/ftp/data");
        prefs.put("rootDirectory","c:/xfiles/ftp/root");
        
        //set Services info
        prefs = Preferences.systemRoot().node("/xbotts/system/services/adminlistener");       
        prefs.put("className","com.webdeninteractive.xbotts.client.serviceproviders.AdminListener");
        prefs.put("type","Admin");
        prefs.putInt("run",1);
        prefs.putInt("port",5800);
                
//-----------------------------------------end system--------------------------------------------->        
        
        //set route info
        prefs = Preferences.systemRoot().node("/xbotts/routes/default");        
        
        //set up xbotts node
        prefs.put("comment","This is the system root");
        prefs.put("company","Webden Interactive");
        prefs.put("destination","localhost");
        prefs.put("key","system");
        prefs.put("outboundRouteKey","system");
        prefs.putInt("runGC",0);
        prefs.put("clientServiceClass","com.webdeninteractive.xbotts.client.serviceproviders.PrintlnClient");

        prefs.putInt("writePrivateLog",0);
        prefs.put("logDirectory","c:/xfiles/logs");
        prefs.put("logLevel","FINEST");
                
        //set notification info
        prefs = Preferences.systemRoot().node("/xbotts/routes/default/notification");
        
        prefs.put("criticalErrorMailToList","");
        prefs.put("errorMailToList","");
        prefs.put("transactionMailToList","");
        prefs.put("translationErrorMailToList","");        
        prefs.putInt("mailOnCriticalError",0);
        prefs.putInt("mailOnError",0);
        prefs.putInt("mailOnTransaction",0);
        prefs.putInt("mailOnTranslationError",0);
        
        //set Translation info
        prefs = Preferences.systemRoot().node("/xbotts/routes/default/translation");

        prefs.put("inboundMapDescriptor","CustomMaps.GeneralTransfer");
        prefs.put("inboundResponseMapDescriptor","CustomMaps.GeneralTransfer");
        prefs.put("outboundMapDescriptor","CustomMaps.GeneralTransfer");
        prefs.put("outboundResponseMapDescriptor","CustomMaps.GeneralTransfer");
                               

//----------------------------------------------------------------
        
        //set route info
        prefs = Preferences.systemRoot().node("/xbotts/routes/fs");        
        
        //set up xbotts node
        prefs.put("comment","This is a file system route");
        prefs.put("company","Webden Interactive");
        prefs.put("destination","c:/xfiles/in");
        prefs.put("key","fs");
        prefs.put("outboundRouteKey","fs");
        prefs.putInt("runGC",0);
        prefs.put("clientServiceClass","com.webdeninteractive.xbotts.client.serviceproviders.FileSystemClient");
        prefs.putInt("writePrivateLog",0);
        prefs.put("logDirectory","c:/xfiles/logs");
        prefs.put("logLevel","FINEST");
        
        //set notification info
        prefs = Preferences.systemRoot().node("/xbotts/routes/fs/notification");
        
        prefs.put("criticalErrorMailToList","");
        prefs.put("errorMailToList","");
        prefs.put("transactionMailToList","");
        prefs.put("translationErrorMailToList","");        
        prefs.putInt("mailOnCriticalError",0);
        prefs.putInt("mailOnError",0);
        prefs.putInt("mailOnTransaction",0);
        prefs.putInt("mailOnTranslationError",0);
        
        //set Translation info
        prefs = Preferences.systemRoot().node("/xbotts/routes/fs/translation");

        prefs.put("inboundMapDescriptor","CustomMaps.GeneralTransfer");
        prefs.put("inboundResponseMapDescriptor","CustomMaps.GeneralTransfer");
        prefs.put("outboundMapDescriptor","CustomMaps.GeneralTransfer");
        prefs.put("outboundResponseMapDescriptor","CustomMaps.GeneralTransfer");

//----------------------------------------------        

        //set route info
        prefs = Preferences.systemRoot().node("/xbotts/routes/ftp");        
        
        //set up xbotts node
        prefs.put("comment","This an ftp system route");
        prefs.put("company","Webden Interactive");
        prefs.put("destination","ftp://wd-016:5802");
        prefs.put("key","ftp");
        prefs.put("outboundRouteKey","fs");
        prefs.putInt("runGC",0);
        prefs.put("clientServiceClass","com.webdeninteractive.xbotts.client.serviceproviders.FTPClientS");
        prefs.putInt("writePrivateLog",0);
        prefs.put("logDirectory","c:/xfiles/logs");
        prefs.put("logLevel","FINEST");
        
        //set notification info
        prefs = Preferences.systemRoot().node("/xbotts/routes/ftp/notification");
        
        prefs.put("criticalErrorMailToList","");
        prefs.put("errorMailToList","");
        prefs.put("transactionMailToList","");
        prefs.put("translationErrorMailToList","");        
        prefs.putInt("mailOnCriticalError",0);
        prefs.putInt("mailOnError",0);
        prefs.putInt("mailOnTransaction",0);
        prefs.putInt("mailOnTranslationError",0);
        
        //set Translation info
        prefs = Preferences.systemRoot().node("/xbotts/routes/ftp/translation");

        prefs.put("inboundMapDescriptor","CustomMaps.GeneralTransfer");
        prefs.put("inboundResponseMapDescriptor","CustomMaps.GeneralTransfer");
        prefs.put("outboundMapDescriptor","CustomMaps.GeneralTransfer");
        prefs.put("outboundResponseMapDescriptor","CustomMaps.GeneralTransfer");
                               

//----------------------------------------------------------------
          
        prefs = Preferences.systemRoot().node("/xbotts");
           
        try {
            // Export the node to a file
            prefs.exportSubtree(new FileOutputStream("testBIE/conf/system.xml"));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (BackingStoreException e) {
            e.printStackTrace();
        }
        System.out.println("done");
   }
}

